package com.yun.datastructure.map.hashmap.leetcode;

import java.util.HashSet;

public class Leetcode136 {
    public int singleNumber1(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int key : nums) {
            if (!set.add(key)) {
                set.remove(key);
            }
        }
        return set.toArray(new Integer[0])[0];
    }

    public int singleNumber(int[] nums) {
        int num = nums[0];
        for (int i = 1; i < nums.length; i++) {
            num = num ^ nums[i];
        }
        return num;
    }
}
